package com.tz.farmer.controller;


import com.smartPark.msframe.result.ResultEx;
import com.tz.farmer.service.WebFarmerKnowledgeService;
import com.tz.farmer.so.FarmerKnowledgeSo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * 食安知识
 */
@Api(tags = "食安知识-web")
@Slf4j
@RestController
@RequestMapping("knowledge")
public class WebFarmerKnowledgeController {



    @Resource
    WebFarmerKnowledgeService webFarmerKnowledgeService;

    /**
     * 添加查询列表
     * @param so
     * @return
     */
    @GetMapping("/listConditions")
    @ApiOperation("条件查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "flag", value = "0:农 1：渔", dataType = "int", defaultValue = "", required = false),
            @ApiImplicitParam(name = "classify", value = "产品品种", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "keyword", value = "关键字", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "releaseTime", value = "时间", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "currentPage", value = "每页条数", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx geKnowledgeListByConditions(FarmerKnowledgeSo so){
        return webFarmerKnowledgeService.geKnowledgeListByConditions(so);
    }

    /**
     * 添加修改软删除
     * @param so
     * @return
     */
    @PostMapping("/editAdd")
    @ApiOperation("添加修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "flag", value = "0：农  1：鱼", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "id", value = "自增id", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "isTop", value = "置顶，搭配传参: id =? flag= ? doFlag = 操作 isTop = 1", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "title", value = "标题", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "classify", value = "产品分类", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "activeText", value = "内容", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "isSued", value = "是否发布 0：草稿 1 ：待发布 2： 已发布", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "doFlag", value = "操作标识1：添加  2 修改", dataType = "string", defaultValue = "", required = true)
    })
    public ResultEx  updateAddKnowledge(@RequestBody FarmerKnowledgeSo so , HttpServletRequest request){
        String token = request.getHeader("TOKEN");
        return webFarmerKnowledgeService.updateAddKnowledge(so,token);
    }


    /**
     * 查看单条记录
     */
    @GetMapping("/selectOne")
    @ApiOperation("查看一条记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "自增id", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getOneDetails(FarmerKnowledgeSo so){
        return webFarmerKnowledgeService.getOneDetails(so);
    }

    /**
     * 硬删除单条记录
     */
    @GetMapping("/deleteOne")
    @ApiOperation("硬删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx deleteOne(FarmerKnowledgeSo so){
        return webFarmerKnowledgeService.deleteOne(so);
    }
}
